package com.guaoran.source.spring.framework.beans;

import com.guaoran.source.spring.framework.aop.AopConfig;
import com.guaoran.source.spring.framework.aop.AopProxy;
import com.guaoran.source.spring.framework.context.BeanPostProcessor;
import com.guaoran.source.spring.framework.core.FactoryBean;

/**
 * @author : 孤傲然
 * @Description :
 *  bean的包装类
 * @date :2018/6/19 18:52
 */
public class BeanWrapper extends FactoryBean {
    //进行aop代理的类
    private AopProxy aopProxy = new AopProxy();
    //还会用到  观察者  模式
    //1、支持事件响应，会有一个监听
    private BeanPostProcessor postProcessor;
    //代理类
    private Object wrapperInstance;
    //原始的通过反射new出来
    private Object originalInstance;
    public BeanWrapper(Object instance){
        //将aop的原始类进行封装，装换成代理进行进行保存
        this.wrapperInstance = aopProxy.getAopProxy(instance);
        //保存原始类
        this.originalInstance = instance;
    }

    /**
     * 将aopConfig信息透传到AopProxy中
     * @param aopConfig
     */
    public void setAopConfig(AopConfig aopConfig){
        aopProxy.setAopConfig(aopConfig);
    }
    public BeanPostProcessor getPostProcessor() {
        return postProcessor;
    }

    public void setPostProcessor(BeanPostProcessor postProcessor) {
        this.postProcessor = postProcessor;
    }

    public Object getWrapperInstance() {
        return wrapperInstance;
    }

    public void setWrapperInstance(Object wrapperInstance) {
        this.wrapperInstance = wrapperInstance;
    }

    public Object getOriginalInstance() {
        return originalInstance;
    }

    public void setOriginalInstance(Object originalInstance) {
        this.originalInstance = originalInstance;
    }


    //返回代理后的class
    public Class<?> getWrapperClass(){
        return wrapperInstance.getClass();
    }
}
